/**
 * 
 */
package net.smartlab.android.callmanager.receivers;

import net.smartlab.android.callmanager.AndroidCallManagerActivity;
import net.smartlab.android.callmanager.R;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.Gravity;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

/**
 * @author placava
 *
 */
public class OutgoingCallReceiver extends BroadcastReceiver {

	/* (non-Javadoc)
	 * @see android.content.BroadcastReceiver#onReceive(android.content.Context, android.content.Intent)
	 */
	 @Override
     public void onReceive(Context context, Intent intent) {
             Bundle bundle = intent.getExtras();
             
             if(null == bundle)
                     return;
             
             String phonenumber = intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER);

             Log.i("OutgoingCallReceiver",phonenumber);
             Log.i("OutgoingCallReceiver",bundle.toString());
             
             String info = "Stai chiamando:\n" + phonenumber;

             LinearLayout layout = new LinearLayout(context);            
             View view = View.inflate(context, R.layout.toast_layout, layout);
             ImageView image = (ImageView) layout.findViewById(R.id.image);
             image.setImageResource(R.drawable.images);
             TextView text = (TextView) layout.findViewById(R.id.text);
             text.setText(info);
             Toast toast = new Toast(context);
             toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0);
             toast.setDuration(Toast.LENGTH_LONG);
             toast.setView(view);
             toast.show();
             
             Intent testActivityIntent = new Intent(context,AndroidCallManagerActivity.class);
             testActivityIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
             context.startActivity(testActivityIntent);
	 }


}
